#pragma once

#include "TextReader.h"
#include "Skeleton.h"
#include "Bone.h"
#include <stack>

#include "rapidxml.hpp"
using namespace rapidxml;
/**
* Reads the bones as exported from 3D Studio Max
* @author Koen Samyn
*/
class BoneReader: public TextReader
{
public:
	/**
	* Creates a new bonereader with the provided filename.
	* @param filename the filename to read.
	*/
	BoneReader(tstring filename);
	/**
	* Destroys the BoneReader object.
	*/
	virtual ~BoneReader(void);
	/**
	* Reads the file, returns true if the read operation was succesful.
	* @return true if reading the file was succesful , false otherwise.
	*/
	bool Read();
	/**
	* Returns the result of this file,namely a skeleton.
	*/
	Skeleton* GetSkeleton(){
		return m_pSkeleton;
	}
protected:
	/**
	* Parses an xml bone element.
	* @param bone the bone to parse.
	*/
	void ParseBone(xml_node<tchar> *bone);
	/**
	* Parses the pivot point.
	* @param pivot the pivot to parse.
	*/
	void ParsePivot(xml_node<tchar> *pivot);
	/**
	* Parses an xml transform element.
	* @param transform the transform to parse.
	*/
	void ParseTransform(xml_node<tchar> *transform);
private:
	/**
	* Pointer to the created skeleton.
	*/
	Skeleton* m_pSkeleton;
	/**
	* Pointer to the current node.
	*/
	SkeletonNode* m_pCurrentNode;
	/**
	* Pointer to the current bone
	*/
	SkeletonNode* m_pCurrentBone;
	/**
	* The stack with the nodes
	*/
	stack<SkeletonNode*> m_NodeStack;
	// -------------------------
	// Disabling default copy constructor and default assignment operator.
	// If you get a linker error from one of these functions, your class is internally trying to use them. This is
	// an error in your class, these declarations are deliberately made without implementation because they should never be used.
	// -------------------------

	BoneReader(const BoneReader& t);
	BoneReader& operator=(const BoneReader& t);
};
